#pragma once

#ifdef LOG_ENABLED

class Logger
{
public:
  static void BeginLog(TCHAR* file);
  static void EndLog();

  static void Log(const TCHAR* d);
  static void Log(int d);
  static void Log(long d);

  static void LogFmt(const TCHAR* fmt, ...);

  static void LogCePropVal(const TCHAR* label, CEPROPVAL& prop);
  static const TCHAR* GetCePropName(CEPROPID propId);

  static void LogTimestamp();
  static void LogLastError();

private:
  static HANDLE hFile;
  static TCHAR  buf[2048];
};

#define BEGINLOG(x) Logger::BeginLog(x)
#define ENDLOG() Logger::EndLog()

#define LOGTIMER_START    DWORD dwLogTimer = ::GetTickCount();
#define LOGTIMER_LOG(x)   Logger::LogFmt(TEXT("%s: %lu"), TEXT(x), ::GetTickCount() - dwLogTimer);
#define LOGTIMER_WLOG(x)   Logger::LogFmt(TEXT("%s: %lu"), x, ::GetTickCount() - dwLogTimer);
#define LOGTIMER_UPDATE   dwLogTimer = ::GetTickCount();

#else

#define BEGINLOG(x)
#define ENDLOG()

#define LOGTIMER_START
#define LOGTIMER_LOG(x)
#define LOGTIMER_UPDATE

#endif